﻿Option Explicit On
Option Strict On

Partial Class private_secure_members_pages_Connect
    Inherits System.Web.UI.Page

    Dim u As MembershipUser
    Dim personId As Int32
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        u = Membership.GetUser(HttpContext.Current.User.Identity.Name)
        Dim getpersonid As New GetPersonIdFromUserId()
        personId = getpersonid.GetPersonId(CType(u.ProviderUserKey, Guid))
        If DropDownList2.SelectedValue Is Nothing Then
            Try
                'NENAD: THIS CODE BELOW MUST ALSO WORK WHEN THE LOGGED IN PERSON IS AN ASSOCIATE
                Dim entityidTA As New LogginsLogDSTableAdapters.usp_GetEntityListFull_ByPersonIdTableAdapter()
                Dim entityidDT As LogginsLogDS.usp_GetEntityListFull_ByPersonIdDataTable
                entityidDT = entityidTA.GetData(personId)

                Dim entityid As Integer = (From entities In entityidDT.AsEnumerable() Select entities).FirstOrDefault().ID
                ObjectDataSource2.SelectParameters("EntityID").DefaultValue = CStr(entityid)
            Catch ex As Exception
                Dim strMessage As String = ex.Message
                Throw ex
            End Try
            
        Else

        End If
    End Sub

    Protected Sub ObjectDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        e.InputParameters("PersonId") = personId
    End Sub

    Protected Sub ObjectDataSource2_Inserted(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource2.Inserted
        Dim insertedid As Integer = CInt(e.OutputParameters("EntityId"))

        Try
            Dim insertpersonentityTA As New LogginsLogDSTableAdapters.usp_PersonEntity_ExpTableAdapter()
            insertpersonentityTA.Insert(personId, insertedid, CType(1, Boolean?))

        Catch ex As Exception
            Dim strMessage As String = ex.Message
            Throw ex
        End Try
        DropDownList2.DataBind()
    End Sub

    Protected Sub ObjectDataSource2_Deleting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource2.Deleting
        'Response.Write(FormView1.SelectedValue.ToString())
        Dim personentitypeexpTA As New LogginsLogDSTableAdapters.SPTableAdapter()
        personentitypeexpTA.usp_PersonEntity_ExpDelete_ByPersonEntityId(personId, CType(FormView1.SelectedValue.ToString(), Integer?))
        Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
        entityTA.Delete(CType(FormView1.SelectedValue.ToString(), Integer?))

        DropDownList2.DataBind()

        e.Cancel = True
    End Sub

    Protected Sub ObjectDataSource2_Updated(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource2.Updated
        DropDownList2.DataBind()
    End Sub

    'Protected Sub FormView1_ModeChanged(sender As Object, e As System.EventArgs) Handles FormView1.ModeChanged
    '    Dim DateCreatedTextBox As TextBox = CType(Me.FormView1.FindControl("DateCreatedTextBox"), TextBox)
    '    Dim EntityTypeIdTextBox As TextBox = CType(Me.FormView1.FindControl("EntityTypeIdTextBox"), TextBox)
    '    Dim ActiveCheckBox As CheckBox = CType(Me.FormView1.FindControl("ActiveCheckBox"), CheckBox)
    '    DateCreatedTextBox.Text = DateTime.Now
    '    EntityTypeIdTextBox.Text = 0
    '    ActiveCheckBox.Checked = True
    'End Sub

    Protected Sub ObjectDataSource2_Inserting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource2.Inserting
        e.InputParameters("DateCreated") = DateTime.Now
        'e.InputParameters("EntityTypeId") = 0
        e.InputParameters("Active") = True

    End Sub
    Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged

    End Sub

    Protected Sub Button6_Click(sender As Object, e As System.EventArgs) Handles Button6.Click
        Dim selectedschedule = "Send Now"
        If Not RadioButton5.Checked Then
            selectedschedule = "Send Later"
            Button9.Visible = True
            Button8.Visible = False
        Else
            Button8.Visible = True
            Button9.Visible = False

        End If

        lblSummary.Text = "You selected:" & DropDownList2.SelectedItem.Value & " entity</br>"
        'lblSummary.Text += "You selected:" & RadioButton7.Text & "</br>"
        'lblSummary.Text += "You selected:" & RadioButton3.Text & "</br>"
        lblSummary.Text += "You selected:" & RadioButton14.Text & "</br>"
        'lblSummary.Text += "You selected:" & RadioButton11.Text & "</br>"
        lblSummary.Text += "You selected:" & selectedschedule & "</br>"
        TabContainer1.ActiveTabIndex = 6
    End Sub

    'Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
    '    'MultiView1.ActiveViewIndex = RadioButtonList1.SelectedValue
    'End Sub


End Class
